package mythesis.controller;



public class FormXML {
	var xml = "";
	
	public function getXML():String
	{
	    return xml;
	}
	
	public function newXML():Void
	{
	    //xml =  "<?xml version=\"1.0\"?>\n";
	    //xml += "<ai>\n"
	    xml = "";
	}
	
	public function startEvent(etype:String):Void
	{
        xml += "   <event type=\"{etype}\">\n";
	}
	
	public function addNumber(etype:String, varname:String):Void
	{
		xml += "      <number>{varname}</number>\n";
	}
	
	public function addWord(etype:String, varname:String):Void
	{
		xml += "      <word>{varname}</word>\n";
	}
	
	public function addTruth(etype:String, varname:String):Void
	{
		xml += "      <truth>{varname}</truth>\n";
	}
	
	public function addCandidate(etype:String, varname:String):Void
	{
		xml += "      <candidate>{varname}</candidate>\n";
	}
	
	public function addTile(line:Number, ttype:String, dtext:String[], dtype:Number[], dvalue:Number[])
	{
	    xml += "      <tile type=\"{ttype}\" line=\"{line}\">\n";
	    for (i in [0..dtype.size()-1])
	    {
	    xml += "         <arg dtype=\"{dtype[i]}\" dvalue=\"{dvalue[i]}\">{dtext[i]}</arg>\n"; 
	    }
	    xml += "      </tile>\n"
	}
	
	public function endEvent():Void
	{
	    xml += "   </event>\n";
	}
	
	public function endXML():Void
	{
	    xml += "</ai>";
	}
	
	/*
	public function addEvent(etype:String):Void
	{
	    var exists = false;
	    for (i in [0..events.size()])
	    {
	        if (events[i] == etype)
	        {
	            exists = true;
	            break;
	        }
	    }
	    if (exists == false)
	    {
	        insert etype into events;
	    }
	}
	
	
	public function addTile(etype:String, line:Number, ttype:String[], tvalue:String[], ttext:String[])
	{
		var eventIndex:Number = -1;
		
		// Search if event exists
		for (i in [0..events.size()])
		{
		    if (events[i] == etype)
		    {
		        eventIndex = i;
		        break;
		    }
		}
		
		// Search if tile is already occupied
		if (eventIndex != -1)
		{
		    for (i in [0..])
		}
	}*/
	
};
